package com 
{
	import flash.events.Event;
	/**
	 * ...
	 * @author Matthew Ladouceur
	 */
	public class RaceInput extends flaInputText
	{
		private var _dictionary:Vector.<String> = new Vector.<String>();
		
		private var ac:AutoComplete;
		private var userInputLength:Number = 0;
		
		public function RaceInput() 
		{
			super();
			
			_dictionary.push("Avian");
			_dictionary.push("Draconian");
			_dictionary.push("Minotaur");
			_dictionary.push("Savar");
			_dictionary.push("Wolven");
			_dictionary.push("Gargylen");
			_dictionary.push("Dwarf");
			_dictionary.push("Dark Elf");
			_dictionary.push("High Elf");
			_dictionary.push("Ice Elf");
			_dictionary.push("Stone Elf");
			_dictionary.push("Wild Elf");
			_dictionary.push("Carnal Fae");
			_dictionary.push("Wood Fae");
			_dictionary.push("Goblin");
			_dictionary.push("Kobold");
			_dictionary.push("Ogre");
			_dictionary.push("Orc");
			_dictionary.push("Ajaunti");
			_dictionary.push("Einher");
			_dictionary.push("Hobling");
			_dictionary.push("Human");
			
			ac = new AutoComplete(_text, _dictionary);
			ac.charBuffer = 1;
			ac.parseDelay = 50;
			ac.addEventListener(Event.CHANGE, onChange);
		}
		
		private function onChange(e:Event):void {
			if (_text.text.length > userInputLength){
				userInputLength = _text.text.length;
				if (ac.completions.length > 0){
					_text.text = _text.text.concat(ac.completions[0].slice(userInputLength));
					_text.setSelection(userInputLength, _text.text.length);
				}
			}else {
				userInputLength = _text.text.length;
			}
			
			for(var i:int = 0; i < ac.completions.length; ++i){
				trace(ac.completions[i]);
			}
			trace("-------------------------");
		}
		
	}

}